package com.zbkj.crmeb.store.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.crmeb.core.exception.CrmebException;
import com.zbkj.crmeb.store.model.StoreProduct;
import com.zbkj.crmeb.store.service.StoreProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zbkj.crmeb.store.dao.StoreProductNormDao;
import com.zbkj.crmeb.store.model.StoreProductNorm;
import com.zbkj.crmeb.store.service.StoreProductNormService;

@Service
public class StoreProductNormServiceImpl extends ServiceImpl<StoreProductNormDao, StoreProductNorm> implements StoreProductNormService {

    @Autowired
    private StoreProductService storeProductService;

    @Override
    public boolean deleteNormProduct(Integer id) {
        StoreProductNorm productNorm = this.getById(id);
        if(productNorm == null){
            throw new CrmebException("该标准商品不存在");
        }
        int count = storeProductService.count(Wrappers.<StoreProduct>lambdaQuery().eq(StoreProduct::getNormId, id));
        if(count > 0){
            throw new CrmebException("该标准商品存在绑定商品，不可删除");
        }
        return this.removeById(id);
    }

}
